$(' .sale label').on('click',function(){
	$(this).addClass('checked').siblings().removeAttr('class');
	var v = $(this).attr('for');
	$('#'+v).show().siblings('.saletype').hide();
});
$(' .pay label').on('click',function(){
	$(this).addClass('checked').siblings().removeAttr('class');
	var v = $(this).attr('for');
	$('#'+v).show().siblings('.payway').hide();
});
var iTime = 59;
var Account;

function writeObj(obj){  

    var description = "";  

    for(var i in obj){    

        var property=obj[i];    

        description+=i+" = "+property+"\n";   

    }    

    alert(description);  

}  

function RemainTime(){
	$('#code').attr('disabled',true);
	var iSecond,sSecond="",sTime="";
	if (iTime >= 0){
		iSecond = parseInt(iTime%60);
		iMinute = parseInt(iTime/60)
		if (iSecond >= 0){
			if(iMinute>0){
				sSecond = iMinute + "分" + iSecond + "秒";
			}else{
				sSecond = iSecond + "秒";
			}
		}
		sTime=sSecond;
		if(iTime==0){
			clearTimeout(Account);
			sTime='获取验证码';
			iTime = 59;
			$('#code').attr('disabled',false);
		}else{
			Account = setTimeout("RemainTime()",1000);
			iTime=iTime-1;
		}
	}else{
		sTime='没有倒计时';
	}
	$('#code').val(sTime);
}

function get_mobile_code(){
	var t = $('#shangmenform').find('.mobile');
	if(!check_mobile(t.val())){
		m(t.focus()); return
	}
	RemainTime();
	// $.post('/api/sms', {mobile:t.val()}, function(msg) {});
	//$.post('/api/login/sms', {mobile:t.val()}, function(msg) {});
		
		$.ajax({
        url: "/api/sms",
        type: "post",
        data: {
            "mobile":t.val()
        },
        beforeSend: function () {
			//alert("开始发送");
        },
        complete: function () {

        },
        success: function (dataResult) {
           // alert(dataResult);
			//alert("123");
        },
        error: function (error) {
// alert(error);
// writeObj(error);
        }
    });
	
	
	
}
$("#shangmenform").on('submit',function(e){
	e.preventDefault();	
	var t = $(this),
	n = t.find('.username'),
	a = t.find('.address'),
	r = t.find('.randcode'),
	p = t.find('.mobile');
	
	if(n.val().trim().length == 0){
		m(n.focus()); return
	}	
	
	if(a.val().trim().length == 0){
		m(a.focus()); return
	}	
	
	if(!check_mobile(p.val())){
		m(p.focus()); return
	}		
	
	if(r.val().trim().length != 6){
		m(r.focus()); return
	}

	$.post(t.attr('action'),t.serializeArray(),function(msg){	
		if(msg.status == 1){
			location.href=msg.data;			
		}
		else{
			alert(msg.info);
		}
	});
});
$('#youjiform').on('submit',function(e){
	e.preventDefault();
	var t = $(this),
	u = t.find('.username'),
	n = t.find('.mobile'),
	ac = t.find('.alicard'),
	an = t.find('.aliname'),
	uc = t.find('.unioncard'),
	un = t.find('.unionname');
	
	if($.trim(u.val()).length == 0){
		m(u.focus());return				
	}
	if($.trim(n.val()).length != 11){
		m(n.focus());return				
	}
	
	var objPay = new Object();
	if($('.pay').find('label.checked').attr('for') == 'alipay'){

		if($.trim(ac.val()).length == 0){
			m(ac.focus());return				
		}
		if($.trim(an.val()).length == 0){
			m(an.focus());return				
		}
		objPay.account_id = ac.val();
		objPay.account_name = an.val();	
		$('.pay_method').val('alipay');
	}
	else{
		if($.trim(uc.val()).length == 0){
			m(uc.focus());return				
		}
		if($.trim(un.val()).length == 0){
			m(un.focus());return				
		}
		objPay.account_id = uc.val();
		objPay.account_name = un.val();
		$('.pay_method').val('unionpay');
	}

	$.post(t.attr('action'),t.serializeArray(),function(msg){
			if(msg.status == 1){
				location.href=msg.data;			
			}
			else{
				alert(msg.info);
			}
		}
	);
});